home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cstrings.arc / MID.C < prev    next >
Encoding:
Text File  |  1985-08-06  |  1.6 KB  |  55 lines

  1. /*
  2.     CSTRINGS.LBR VERSION 1.0
  3.     Spark Software, Inc.
  4.  
  5.         If you find this software of use, it is requested that you send
  6.         a donation ($10.00 suggested) to:
  7.  
  8.             Spark Software, Inc.
  9.             24 Royal Crest Dr., #5
  10.             Nashua, NH  03060
  11.  
  12.         Upon receiving your donation, your name will be added to the 
  13.         List of Registered Users, and future updates can be obtained
  14.         from the SPARKIE RBBS at (603) 888-8179.
  15.  
  16.         If you include an extra $10.00 with your donation, the newest
  17.         version of CSTRINGS.LBR will be mailed to you.
  18.  
  19.         Call SPARKIE RBBS at the number above for other Spark Software
  20.         products!!!
  21. */
  22.  
  23. /*
  24.  *    char *
  25.  *    mid (dest, str, pos, n)
  26.  *    char *dest, *str;
  27.  *    int pos, n;
  28.  *
  29.  *    This function works very much like the BASIC function MID$.
  30.  *    It returns a pointer to a character stringing containing n
  31.  *    characters (null padded if needed) from str starting from position
  32.  *    pos (remember:    since C is zero based, the first position is
  33.  *    postion 0, not position 1).  The new string (dest) is assumed
  34.  *    to be large enough to hold the result.    Not also the external
  35.  *    declaration of strncpy.  This is needed for Lattice C large
  36.  *      model copilation to work (since int's and char *'s are not the
  37.  *    same size in that memory model).
  38.  */
  39.  
  40. char *mid (dest, str, pos, n)
  41. register char *dest, *str;
  42. register int pos, n;
  43. {
  44.     extern char *strncpy ();
  45.  
  46.                     /* Do a strncpy () to fill
  47.                        the new string with the
  48.                        proper characters */
  49.     new_string = strncpy (dest, &str[pos], n);
  50.  
  51.                     /* Return the pointer to the result */
  52.     return (dest);
  53.  
  54. } /* mid */
  55.